var limsSampleHandle = Gikam.getPageObject({

    baseUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/sample-handles',
    sampleUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/samples',
    boardUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/location-boards',
    batchUrl: IFM_CONTEXT + '/secure/basemodule/business/batchs',

    workflow: {
        dbTable: 'T_LIMS_SAMPLE_HANDLE',
        columns: [{
            field: 'id',
            title: 'T_LIMS_SAMPLE_HANDLE.ID'
        }]
    },

    getBackEditListColumns: function () {
        return [{
            checkbox: true
        }, {index: true}, Gikam.status.getBpmnColumn(limsSampleHandle.workflow.dbTable), {
            field: 'handleCode',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDELCODE',
            width: 140,
            type: 'link'
        }, {
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK',
            validators: ['notEmpty'],
            width: 300,
            editor: true
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_SAMPLE_HANDLE.COURIERNUMBER',
            width: 140,
            editor: true
        }, {
            field: 'courierCompany',
            title: 'T_LIMS_SAMPLE_HANDLE.COURIERCOMPANY',
            editor: true,
            type: 'select',
            width: 140,
            category: 'sys',
            param: {
                codeCategoryId: 'courierCompany'
            }
        }, {
            field: 'recipient',
            title: 'T_LIMS_SAMPLE_HANDLE.RECIPIENT',
            // validators: ['notEmpty'],
            width: 140,
            editor: true
        }, {
            field: 'phone',
            title: 'T_LIMS_SAMPLE_HANDLE.PHONE',
            // validators: ['notEmpty'],
            width: 140,
            editor: true
        }, {
            field: 'address',
            title: 'T_LIMS_SAMPLE_HANDLE.ADDRESS',
            // validators: ['notEmpty'],
            width: 140,
            editor: true
        }, {
            field: 'createdByName',
            width: 140,
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYNAME'
        }, {
            field: 'createdTime',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDTIME',
            width: 160,
            type: 'dateTime'
        }, {
            field: 'createdByOrgName',
            width: 140,
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYORGNAME'
        }];
    },

    getEditListColumns: function (pageType) {
        var gridStructPartOne = [{
            checkbox: true
        }, {index: true}, Gikam.status.getBpmnColumn(limsSampleHandle.workflow.dbTable), {
            field: 'handleCode',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDELCODE',
            type: 'link'
        }, {
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK',
            validators: ['notEmpty'],
            width: 300,
            editor: true
        }]
        if (pageType && pageType === 'out') {
            gridStructPartOne.push({
                field: 'sampleOutTime',
                title: 'T_LIMS_SAMPLE_HANDLE.SAMPLEOUTTIME',
                type: 'dateTime',
                width: 140,
                editor: true
            })
        }
        var gridStructPartTwo = [{
            field: 'createdByName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYNAME'
        }, {
            field: 'createdTime',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDTIME',
            width: 160,
            type: 'dateTime'
        }, {
            field: 'createdByOrgName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYORGNAME'
        }]
        return gridStructPartOne.concat(gridStructPartTwo)
    },

    getBaseInfoFormFields: function (type) {
        return [/*{
            field : 'handleType',
            title : 'T_LIMS_SAMPLE_HANDLE.HANDLETYPE',
            validators : [ 'strLength[0,11]' ]
        }, */{
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK',
            validators: ['strLength[0,100]']
        }, {
            field: 'recipient',
            title: 'T_LIMS_SAMPLE_HANDLE.RECIPIENT',
            validators: ['strLength[0,33]']
        }, {
            field: 'phone',
            title: 'T_LIMS_SAMPLE_HANDLE.PHONE',
            validators: ['strLength[0,33]']
        }, {
            field: 'address',
            title: 'T_LIMS_SAMPLE_HANDLE.ADDRESS',
            validators: ['strLength[0,66]']
        },];
    },

    getAuditListColumns: function (pageType) {
        var gridStructPartOne = [{
            checkbox: true
        }, {index: true}, Gikam.status.getBpmnColumn(limsSampleHandle.workflow.dbTable), {
            field: 'handleCode',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDELCODE',
            type: 'link'
        }, {
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK',
            width: 300,
        }]
        if (pageType && pageType == 'out') {
            gridStructPartOne.push({
                field: 'sampleOutTime',
                title: 'T_LIMS_SAMPLE_HANDLE.SAMPLEOUTTIME',
                type: 'dateTime',
                width: 160,
            })
        }
        var gridStructPartTwo = [{
            field: 'createdByName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYNAME'
        }, {
            field: 'createdTime',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDTIME',
            width: 160,
            type: 'dateTime'
        }, {
            field: 'createdByOrgName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYORGNAME'
        }]
        return gridStructPartOne.concat(gridStructPartTwo)
    },

    getBackAuditListColumns: function () {
        return [{
            checkbox: true
        }, {index: true}, Gikam.status.getBpmnColumn(limsSampleHandle.workflow.dbTable), {
            field: 'handleCode',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDELCODE',
            type: 'link'
        }, {
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK',
            width: 300,
        }, {
            field: 'recipient',
            title: 'T_LIMS_SAMPLE_HANDLE.RECIPIENT'
        }, {
            field: 'phone',
            title: 'T_LIMS_SAMPLE_HANDLE.PHONE'
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_SAMPLE_HANDLE.COURIERNUMBER',
            editor: true
        }, {
            field: 'courierCompany',
            title: 'T_LIMS_SAMPLE_HANDLE.COURIERCOMPANY',
            editor: true,
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'courierCompany'
            }
        }, {
            field: 'address',
            title: 'T_LIMS_SAMPLE_HANDLE.ADDRESS'
        }, {
            field: 'createdByName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYNAME'
        }, {
            field: 'createdTime',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDTIME',
            width: 160,
            type: 'dateTime'
        }, {
            field: 'createdByOrgName',
            title: 'T_LIMS_SAMPLE_HANDLE.CREATEDBYORGNAME'
        }];
    },

    getSearchListColumns: function () {
        return [{
            checkbox: true
        }, {index: true}, Gikam.status.getBpmnColumn(limsSampleHandle.workflow.dbTable), {
            field: 'handleCode',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDELCODE',
            type: 'link'
        }, {
            field: 'handleType',
            title: 'T_LIMS_SAMPLE_HANDLE.HANDLETYPE'
        }, {
            field: 'remark',
            title: 'T_LIMS_SAMPLE_HANDLE.REMARK'
        }, {
            field: 'recipient',
            title: 'T_LIMS_SAMPLE_HANDLE.RECIPIENT'
        }, {
            field: 'phone',
            title: 'T_LIMS_SAMPLE_HANDLE.PHONE'
        }, {
            field: 'address',
            title: 'T_LIMS_SAMPLE_HANDLE.ADDRESS'
        }];
    },

    getSampleListColumns: function (editor, pageType) {
        var enter = false
        if (pageType && pageType === 'enter') {
            enter = true
        }
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE',
            width: 140,
            styleFormatter: function (row) {
                if (row.ext$.isscancodecheckover && row.ext$.isscancodecheckover == 'true') {
                    return {backgroundColor: 'green'}
                }
            }
        }, {
            field: 'sampleType',
            title: 'T_LIMS_SAMPLE.SAMPLETYPE',
            width: 140,
        }, {
            field: 'ext$.batchcode',
            title: 'T_LIMS_BATCH.BATCHCODE',
            width: 140,
            type: 'link'
        }, {
            field: 'ext$.locationdesc',
            title: 'T_LIMS_SAMPLE.LOCATIONS2',// 存放位置
            width: 140,
        }, {
            field: 'locations',
            title: 'T_LIMS_SAMPLE.LOCATIONS',
            width: 140,
            editor: editor,
            type: 'choose',
            category: 'board-choose',
            single: true,
            onAfterChoose: function (data, index) {
                var _this = this;
                if (!Gikam.isEmpty(data)) {
                    let activedRow = this.getData()[index];
                    data.sampleId = activedRow.id;
                    workspace.window.showMask();
                    Gikam.postText(limsSampleHandle.boardUrl + "/update-samples-single", Gikam.getJsonWrapper({}, [null, [data]])).done(function (data) {
                        _this.refreshRowById(activedRow.id);
                    }).always(function () {
                        workspace.window.closeMask();
                    });
                }
            },
            onClean: function (field, value, index) {
                var _this = this;
                let activedRow = this.getData()[index];
                workspace.window.showMask();
                Gikam.postText(limsSampleHandle.boardUrl + "/clean-samples", Gikam.getJsonWrapper({}, [null, [activedRow]])).done(function (data) {
                    _this.refreshRowById(activedRow.id);
                }).always(function () {
                    workspace.window.closeMask();
                });
            },
        },/* {
            field: 'ext$.sampleconcentration_temp',
            title: 'T_LIMS_SAMPLE.SAMPLECONCENTRATION',
            editor: enter,
            width: 140,
            onChange: function (field, value, index, oldValue, text) {
                var grid = this
                var data = grid.options.data[index]
                let handleRow = Gikam.getComp(pageType + 'lims-sample-handle-edit-list-grid').getActivedRow()
                // 不触发自动保存
                this.setData({
                    index: index,
                    ext$: {
                        sampleconcentration_temp: value
                    }
                }, false);
                console.log(data)
                workspace.window.showMask()
                Gikam.postText(limsSampleHandle.baseUrl + '/update/sampledata',
                    Gikam.getJsonWrapper({
                        oldValue: oldValue,
                        field: 'sampleConcentration',
                        handleId: handleRow.id,
                        sampleConcentration: value
                    }, ['', [data]])).done(function () {
                    grid.refresh()
                }).always(function () {
                    workspace.window.closeMask()
                })
            }
        }, {
            field: 'ext$.samplevolume_temp',
            title: 'T_LIMS_SAMPLE.SAMPLEVOLUME',
            editor: enter,
            width: 140,
            onChange: function (field, value, index, oldValue, text) {
                var grid = this
                var data = grid.options.data[index]
                let handleRow = Gikam.getComp(pageType + 'lims-sample-handle-edit-list-grid').getActivedRow()
                // 不触发自动保存
                this.setData({
                    index: index,
                    ext$: {
                        samplevolume_temp: value
                    }
                }, false)
                workspace.window.showMask()
                Gikam.postText(limsSampleHandle.baseUrl + '/update/sampledata',
                    Gikam.getJsonWrapper({
                        oldValue: oldValue,
                        field: 'sampleVolume',
                        handleId: handleRow.id,
                        sampleVolume: value
                    }, ['', [data]])).done(function () {
                    grid.refresh()
                }).always(function () {
                    workspace.window.closeMask()
                })
            }
        }, {
            field: 'ext$.restcount_temp',
            title: 'T_LIMS_SAMPLE.RESTCOUNT',
            editor: enter,
            width: 140,
            onChange: function (field, value, index, oldValue, text) {
                var grid = this
                var data = grid.options.data[index]
                let handleRow = Gikam.getComp(pageType + 'lims-sample-handle-edit-list-grid').getActivedRow()
                // 不触发自动保存
                this.setData({
                    index: index,
                    ext$: {
                        restcount_temp: value
                    }
                }, false)
                workspace.window.showMask()
                Gikam.postText(limsSampleHandle.baseUrl + '/update/sampledata',
                    Gikam.getJsonWrapper({
                        oldValue: oldValue,
                        field: 'restCount',
                        handleId: handleRow.id,
                        restCount: value
                    }, ['', [data]])).done(function () {
                    grid.refresh()
                }).always(function () {
                    workspace.window.closeMask()
                })
            }
        }*/];
    },

    getSearchSampleListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE',
            width: 140,
            styleFormatter: function (row) {
                var color = '';
                if (row.ext$.isscancodecheckover && row.ext$.isscancodecheckover == 'true') {
                    color = 'green'
                } else if (row.isscancodecheckover && row.isscancodecheckover == 'true') {
                    color = 'green'
                }
                return {backgroundColor: color}
            }
        }, {
            field: 'ext$.batchcode',
            title: 'T_LIMS_BATCH.BATCHCODE',
            width: 140,
            type: 'link'
        }, {
            field: 'collectTime',
            title: 'T_LIMS_SAMPLE.COLLECTTIME',
            width: 140,
            preInsert: true,
            type: 'dateTime'
        }, {
            field: 'ext$.locationdesc',
            width: 140,
            title: 'T_LIMS_SAMPLE.LOCATIONS2',// 存放位置
        }, {
            field: 'ext$.locations',
            title: 'T_LIMS_SAMPLE.LOCATIONS',
            width: 140,
        }, {
            field: 'sampleType',
            width: 140,
            title: 'T_LIMS_SAMPLE.SAMPLETYPE',
        }, {
            field: 'samplingPosition',
            title: 'T_LIMS_SAMPLE.SAMPLINGPOSITION',
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'samplingPosition'
            },
            width: 140,
        }, {
            field: 'receiveAbnomalRemark',
            title: 'T_LIMS_SAMPLE.RECEIVEABNOMALREMARK',
            width: 140,
        }];
    },

    getFlowListColumns: function () {
        return [{
            index: true
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.CANDIDATOR.TASKNAME',
            field: 'taskName',
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.CANDIDATOR.USER',
            field: 'auditedByName'
        }, {
            title: 'T_CORE_INTERNAL_AUDIT.AUDITDATE',
            field: 'auditedTime',
            width: 140
        }, {
            title: 'GIKAM.WORKFLOW.PASS.OPINION.TITLE',
            field: 'comment',
            width: 300
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.COMMENT.ROUTE',
            field: 'route',
            width: 140
        }]
    },

    loadBatchDetailPage: function (row) {
        Gikam.create('modal', {
            height: '90%',
            width: '90%',
            title: 'BASELINE.BUSINESS.BATCH.MODAL.DETAIL',
            url: limsSampleHandle.batchUrl + '/page/detail-top' + Gikam.param({
                id: row.ext$.batchid,
                topPage: '1'
            }),
        })
    },

    loadSampleHandleDetailPage: function (row, pageType, step) {
        workspace.window.load(Gikam.printf(limsSampleHandle.baseUrl + '/page/{pageType}/detail', {pageType: pageType}) + Gikam.param({
            id: row.id,
            step: step
        }))
    }
});
